package de.mpii.html.table;

import java.util.ArrayList;
import java.util.List;

import de.mpii.util.Uformat;

public class Table {

	private final List<ComplexColumn> columns = new ArrayList<ComplexColumn>();
	private final List<Row> rows = new ArrayList<Row>();

	public Table() {

	}

	public void add(Row row) {
		rows.add(row);
	}

	public List<ComplexColumn> getColumns() {
		return columns;
	}

	@Override
	public String toString() {
		StringBuilder sbuilder = new StringBuilder();

		sbuilder.append(String.format("TABLE (%d,%d)", rows.size(),
				columns.size()));

		for (ComplexColumn col : columns)
			sbuilder.append(String.format("%s, ", col));

		sbuilder.append('\n');

		sbuilder.append(Uformat.repeat("_", 50));
		sbuilder.append('\n');

		for (Row row : rows) {
			sbuilder.append(row);
			sbuilder.append('\n');
		}

		sbuilder.append(Uformat.repeat("_", 50));
		sbuilder.append('\n');

		return sbuilder.toString();
	}
}
